package cn.xd.base.application.service.query.impl;

import cn.hutool.core.util.ObjUtil;
import cn.xd.base.application.service.query.GlobalAppUserQueryAppService;
import cn.xd.base.basic.type.GlobalAppUserId;
import cn.xd.base.domain.entity.GlobalAppUser;
import cn.xd.base.domain.repository.GlobalAppUserRepository;
import cn.xd.base.persistence.dos.GlobalAppUserDO;
import cn.xd.base.persistence.mps.GlobalAppUserMpService;
import cn.xd.core.response.ObjectResult;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

@Service
public class GlobalAppUserQueryAppServiceImpl implements GlobalAppUserQueryAppService {

    @Resource
    private GlobalAppUserMpService globalAppUserMpService;
    @Resource
    private GlobalAppUserRepository globalAppUserRepository;

    @Override
    public ObjectResult<GlobalAppUser> getGeneralUserByPhone(String phone) {
        GlobalAppUserDO globalAppUserDO = globalAppUserMpService.findByPhone(phone, null).get();
        if (ObjUtil.isEmpty(globalAppUserDO)) {
            return ObjectResult.of(null);
        }
        return globalAppUserRepository.find(GlobalAppUserId.of(globalAppUserDO.getId()));
    }

}
